/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sys.utils;

import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import org.ini4j.Ini;
import static sys.utils.Utils.dirFileConfig;

/**
 *
 * @author Cesar Daniel
 */
public class ConexaoADS {

    //Vem como parametro a sessão para conexao selecionada na combobox
    public static String section;

    public static Connection getConection() throws SQLException, IOException {

        String server;
        String directory;
        String port;

        Ini ini = new Ini(new File(dirFileConfig()));
        server = ini.get(section, "server/ip");
        directory = ini.get(section, "directory");
        port = ini.get(section, "port");

        try {
            Class.forName("com.extendedsystems.jdbc.advantage.ADSDriver");
            return DriverManager.getConnection("jdbc:extendedsystems:advantage://" + server + ":" + port + ";catalog=" + directory + ";TableType=cdx;LockType=compatible;");
        } catch (SQLException | ClassNotFoundException ex) {
            throw new SQLException(ex.getMessage());
        }
//         try {
//            Class.forName("com.extendedsystems.jdbc.advantage.ADSDriver");
//            return DriverManager.getConnection("jdbc:extendedsystems:advantage://192.168.1.46:6262;catalog=C:\\spac\\EMP91;TableType=cdx;LockType=compatible;");
//        } catch (SQLException | ClassNotFoundException ex) {
//            throw new SQLException(ex.getMessage());
//        }
    }
}
